{include file='edit.tpl'}

<div id='roles'></div>

{literal}
<script id='roles_tpl' type="text/x-jsmart-tmpl">
	{foreach $allRoles as $role}
		<div>
			<input type=checkbox name='roles[{$role[0]}]' {if $userRoles[$role[0]]}checked{/if}>&nbsp;{$role[1]}
		</div>
	{/foreach}
</script>
{/literal}

<script>
	createTabs = function() {
		addTab('roles','Группы');
	}
	
	$( function() {
		setFirstTabTitle('Пользователь');
		
		$.when(
			call('admin.getList', { id:'roles', brief:1, noHeader:1 }),
			call('admin.getList', { id:'roles_of_user', brief:1, noHeader:1, params: { 'id':('id' in k ? k.id : 0) } })
		).done( function(data1, data2) {
			var userRoles = {};
			for (var i=0; i<data2[0].length; ++i) {
				userRoles[ data2[0][i][0] ] = true;
			}
			$('#roles').html( $('#roles_tpl').html().fetch( { allRoles:data1[0], 'userRoles':userRoles } ) );
		} );
		
	} );
	
</script>